<template>
  <div class="clearfix table-out">
    <div class="clearfix out-con">
      <el-button
        type="primary"
        plain
        size="small"
        class="return pointer"
        @click="returnGo"
        ><i class="iconfont icon-fanhui"></i> 返回
      </el-button>
      <top-step ref="topStepRef"></top-step>
      <div class="clear h20"></div>
      <div class="fxl left-main clearfix">
        <form-data ref="formDataRef" @getPdf="getPdf"></form-data>
      </div>
      <div class="fxr right-main pos-rel clearfix">
        <div class="clearfix top_line">资料审核</div>
        <el-select :disabled="pingszt=='2'" v-model="zilshjg" placeholder="请选择资料审核结果">
          <el-option
            v-for="item in options"
            :key="item.itemValue"
            :label="item.itemText"
            :value="item.itemValue"
          >
          </el-option>
        </el-select>
        <div class="clear h20"></div>
        <div class="but-out clearfix">
          <el-button type="primary"  class="submit-big two" v-if="pingszt==0" @click="submit(1)">保存</el-button>
          <el-button type="primary" class="submit-big two" @click="audit">审核</el-button>
        </div>
      </div>
      <div class="clear h20"></div>
      <form-data-pdf
          v-show="pdfStatic"
          :pdfTitle="pdfTitle"
          :pdf-title-sub="pdfTitleSub"
          :form-data="pdfData"
          ref="formDataPdfRef"
      ></form-data-pdf>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import pubJs from "./pub";
export default {
  mixins: [pubJs],
  data() {
    return {
      zilshjg: null,
      options: [],
      id: null,
      pingwlb: [],
      pingy: null,
      zongf: 0.0,
      guizfs: {},
      pingsgz: [],
      formData2: {},
      canszpId: null,
      formData: {},
      formDefine: [],
      daqsc: null,
      saisId: null,

      topData: [],
      menuSelect: 0,
      activeName: 0,
      pingszt:'',
    };
  },

  inject: ["imageUrl", "serviceUrl"],

  mounted() {
    this.saisjcId = this.$route.query.saisjcId;
    this.id = this.$route.query.id;
    this.canszpId = this.$route.query.canszpId;
    this.saisId = this.$route.query.saisId;
    this.pingszt =this.$route.query.pingszt;
    this.zilshjg = this.$route.query.zilshjg;

    this.$refs["topStepRef"].getList(
      {
        saisId: this.saisId,
      },
      "pings"
    );
    this.$refs["formDataRef"].getFormDefine(
      {
        saisId: this.saisId,
        cansrsf: this.userInfo.cansrsf,
      },
      "pings",this.pingszt
    );
    this.$refs["formDataRef"].getFormData(
      {
        saisId: this.saisId,
        canszpId: this.canszpId,
      },
      "pings",this.pingszt
    );


    let that = this;

    axios
      .get(that.serviceUrl + "/sys/dictItem/list", {
        headers: {
          "X-Access-Token": localStorage.getItem("token"),
        },
        params: {
          dictId: "1780588172500619266",
          _t: new Date().getTime(),
        },
      })
      .then((resp) => {
        that.options = resp.data.result.records;
      })
      .catch((error) => {
        //console.log(error);
      });
  },

  methods: {
    submit(num){
      this.btnLoading = true
      let that = this;
      const config = {
        headers: {
          "X-Access-Token": localStorage.getItem("token"),
        },
      };
      let _formData = that.$refs["formDataRef"].formData;
      axios
          .put(
              that.serviceUrl + "/saisjczd2/cbda2Saisjczd/editFormData4Zilsh",
              { data: JSON.stringify(_formData) },
              config
          )
          .then((resp) => {
            console.log(resp);
            if (resp.data.success) {
              this.btnLoading = false
              if(num==1){
                that.$message.success("保存成功");
                that.returnGo()
              }else{
                this.zuopinExportPdf(resp.data.result);
              }
            } else {
              that.$message.error(resp.data.message);
            }
          })
          .catch((error) => {
            this.$message.warning(error)
            //console.log(error);
          });
    },


    audit() {
      let that = this;
      this.btnLoading = true
      const config = {
        headers: {
          "X-Access-Token": localStorage.getItem("token"),
        },
      };

      let data = {
        saisjcId: that.saisjcId,
        saisId: that.saisId,
        zilshjg: that.zilshjg,
        id: that.id,
      };

      axios
        .put(
          that.serviceUrl + "/zilsh2/cbda2Zilsh/audit",
          data,
          config
        )
        .then((resp) => {
          console.log(resp);
          if (resp.data.success) {
            that.$message.success("成功");
            this.btnLoading = false
            that.returnGo()
            // that.$router.push("/pc/zilsh_detail?saisId="+ this.saisId);
          } else {
            that.$message.error(resp.data.message);
          }
        })
        .catch((error) => {
          //console.log(error);
        });
    },
    menuChange(item, index) {
      this.menuSelect = index;
      console.log(item, index);
    },
    returnGo() {
      this.$router.go(-1); // 返回上一个页面
    },
  },
};
</script>

<style scoped lang="less">
.left-main {
  width: 75%;
}
.right-main {
  width: calc(25% - 70px);
  background: #fff;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  padding: 20px;
}
.pf-list {
  .line {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin: 0px 0px 10px 0px;
  }
  .num-font {
    width: 120px;
    font-weight: bold;
  }
  .num-inp {
    width: 100px;
  }
  .intro {
    width: 100%;
    display: block;
    opacity: 0.8;
    margin: 0px 0px 20px 0px;
  }
}
.top_line {
  font-size: 18px;
  font-weight: bold;
  border-bottom: 1px dashed #ccc;
  padding: 0px 0px 5px 0px;
  margin: 0px 0px 10px 0px;
}
.pw-icon {
  .icon {
    padding: 10px;
    i {
      font-size: 30px;
      &.focus {
        color: #3967ff;
      }
    }
  }
}
</style>
